package org.emergency.framework.common;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.emergency.framework.dao.oa.ITbIdsDAO;
import org.emergency.framework.model.TbIds;
import org.springframework.stereotype.Service;

@Service("idsServiceImpl")
public class IdsServiceImpl implements IdsService{
	private static final Log log = LogFactory.getLog(IdsServiceImpl.class);
	/**
	 * 主键维护类的DAO
	 */
	@Resource(name="tbIdsDAO")
	private ITbIdsDAO tbIdsDAO;

	/**
	 * 获取表主键的方法 传入参数：主键维护表行数，参照IDUtil类取静态字段值 返回：目标表主键当前值
	 */
	public String findTablePK(int id) {
		log.debug("getting table primary key with id: " + id);
		try {
			TbIds ids = tbIdsDAO.findById(id);
			String tablePK = ids.getTableIdValue();
			Long tmp = Long.valueOf(tablePK);
			ids.setTableIdValue((++tmp).toString());
			tbIdsDAO.attachDirty(ids);
			return tablePK;
		} catch (RuntimeException re) {
			log.error("get failed", re);
		}
		return null;
	}

}
	

